//
// Created by dawn on 2025/4/11.
//

#ifndef SHOPMENU_H
#define SHOPMENU_H
#include <Cart.h>
#include <ItemService.h>
#include <vector>
#include "Item.h"
#include "MainMenu.h"
#include <cmath>
#include <set>
#include <sstream>


class ShopMenu final : public Menu{
public:
    struct PageView {
        int item_number = 0;
        int number_per_page = 2;
        int current_page_number = 0;
        int total_pages = 0;
    };

    explicit ShopMenu(ItemService &item_service, const MainMenu::AppState &app_state);
    [[nodiscard]] std::string titleToken(const std::string &token= "") const;
    void display() const override;
    void run() const override;
    void showPage() const;
    void nextPage();
    void prevPage();
    void showAllItems(bool isLoggedIn);
    void searchByName();
    void searchByCategory();
    void searchByPrice();
    void cartItem();
    void updateCartItem();
    void deleteCartItem();
    void showCartMenu();
    void updateCart() const;
    void buyMenu() const;
    void buySingleItem() const;
    void buyMultiItem() const;
    void buyCart();

private:
    Account account;
    ItemService &item_service;
    std::vector<Item> shop_items;
    PageView page_view;
    int view_state = 0; // 0:Browsing 1:all items 2:search by name (and by desc) 3:search by category 4:search by price
    Cart cart;
};



#endif //SHOPMENU_H
